home *** CD-ROM | disk | FTP | other *** search
- Path: camelot.ccs.neu.edu!will
- From: will@ccs.neu.edu (William D Clinger)
- Newsgroups: comp.lang.c
- Subject: Re: C compilers which optimize tail calls (was: GOTO controversy)
- Date: 9 Apr 1996 18:43:16 GMT
- Organization: College of CS, Northeastern University
- Message-ID: <4keb44$86h@camelot.ccs.neu.edu>
- References: <oun34tm3c7.fsf@lynx.cs.byu.edu> <DpCv8o.9Mw@ida.liu.se> <ouivfcnaxq.fsf@lynx.cs.byu.edu>
- NNTP-Posting-Host: krakatoa.ccs.neu.edu
-
- In article <ouivfcnaxq.fsf@lynx.cs.byu.edu>
- hall@cs.byu.edu (Kelly Hall) writes:
- > Rickard> All in all, I don't think it's wise to assume that tail
- > Rickard> call optimization is done by the typical C compiler.
- >
- >I stand corrected. So why haven't more C compiler folks added this
- >useful optimization?
-
- Stack allocation of mutable variables and data often
- interferes with proper tail recursion. Consider
-
- int f (int n) {
- int A[10];
- int i;
- for (i = 0; i < 10; i = i + 1)
- A[i] = n * i;
- return g (&n, &(A[0]));
- }
-
- Yes, it is possible to write a correct C compiler that
- compiles the tail-recursive call to g as a tail recursion.
- The compiler technology required to do this, however, would
- be considered bizarre (or even broken) by most C programmers.
-
- I very much doubt whether any production C compiler
- can be relied upon to generate properly tail recursive code.
-
- William D Clinger
-